//
//  WeekDayView.swift
//  AirlineReservation
//
//  Created by Kevin on 2020/1/24.
//  Copyright © 2020 Kevin. All rights reserved.
//

import UIKit

class WeekDayView: UIView {
    
    // 常量
    private let num = 7
    private var weekDayLabels = [UILabel]()
    private let weekDays = ["日","一","二","三","四","五","六"]
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        init_views()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func layoutSubviews() {
        // 宽度
        let w = frame.width / 7
        // 开始摆放
        for i in 0..<num {
            let label = weekDayLabels[i]
            label.frame = CGRect(x: w * CGFloat(i), y: 0, width: w, height: frame.height)
        }
    }
}

extension WeekDayView {
    
    private func init_views() -> Void {
        
        for i in 0..<num {
            let label = UILabel()
            label.text = weekDays[i]
            label.textAlignment = .center
            label.font = UIFont.systemFont(ofSize: 13)
            if i == 0 || i == 6 {
                label.textColor = COLOR_RED
            }else {
                label.textColor = COLOR_NICE
            }
            // 添加到父控件
            addSubview(label)
            weekDayLabels.append(label)
        }
    }
}
